package com.cskaoyan;

import com.cskaoyan.bean.User;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;

/**
 * 创建日期: 2022/04/27 10:02
 *
 * @author ciggar
 */
public class MybatisMain {

    public static void main(String[] args) {

        SqlSessionFactoryBuilder sqlSessionFactoryBuilder = new SqlSessionFactoryBuilder();
        InputStream inputStream = MybatisMain.class.getClassLoader().getResourceAsStream("mybatis-config.xml");
        SqlSessionFactory sqlSessionFactory = sqlSessionFactoryBuilder.build(inputStream);


        // 获取SqlSession
        SqlSession sqlSession = sqlSessionFactory.openSession();



        // 发送SQL、获取结果、封装结果到User对象里面
        User user = sqlSession.selectOne("cskaoyan.bbb",30);

        System.out.println(user);


        // 关闭
        sqlSession.close();

    }
}
